/* This file is part of the cppuccino C++ framework
Copyright (C) 2008-2011 by Dagobert Premier

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef _CPPUCCINO_UNDERTRUEFALSE_H_
#define _CPPUCCINO_UNDERTRUEFALSE_H_

namespace cppuccino
{

    const int undef = -1 ;

    class undeftruefalse
    {
    public:
        undeftruefalse() : m_val(undef) {}
        void operator=(bool b) 
        {
            m_val=b?1:0;
        }
        void operator=(int i)
        {
            if ( i == undef )
            {
                m_val = undef ;
            }
            else
            {
                m_val = (i==0)?0:1 ;
            }
        }
        bool isundef()
        {
            return m_val == undef ;
        }
        void operator++
        {
            if ( m_val == 1 )
            {
                m_val = undef ;
            }
            else
            {
                ++m_val ;
            }
        }
        void operator--
        {
            if ( m_val == undef )
            {
                m_val = 1 ;
            }
            else
            {
                --m_val;
            }
        }
        bool operator==(const undeftruefalse& utf)
        {
            return m_val == utf.m_val ;
        }
        bool operator==(const bool& b)
        {
            if ( m_val == undef )
            {
                return false ;
            }
            else
            {
                return b?(m_val==1):(m_val==0) ;
            }
        }
        bool operator==(const int& i)
        {
            return m_val == i ;
        }
        int m_val ;
    } ; // class undeftruefalse

} // namespace cppuccino



#endif // _CPPUCCINO_UNDERTRUEFALSE_H_

